#include "stdafx.h"
#include "SpriteBreathBar.h"
#include "StructureAndConst.h"
#include "SpriteSingleFrame.h"
#include "SpriteMultiFrame.h"
#include "SpriteStretch.h"
#include "DisplayController.h"
#include "SpriteStaticPercent.h"
SpriteBreathBar::SpriteBreathBar(int nLayer):SpriteCombined(nLayer),
	m_pBlood(NULL),m_pEnd(NULL)
{
	LPDIRECT3DTEXTURE9 pTexture=NULL;
	SpriteSingleFrame* p=NULL;
	CREATE_SPRITE_SINGLE_FRAME(p,ptBREATH_BK,picBREATH_BK,nLayer,true,false,JUDGE_POINTER_RE_VOID);
	//p->SetCenter(D3DXVECTOR2(picCOLLECT_UFO.nWidth/2.0f,0.0f));
	AddSprite(p);

	CREATE_SPRITE_STATIC_PERCENT(m_pBlood,ptBREATH_BLOOD,picBREATH_BLOOD,nLayer,true,false,JUDGE_POINTER_RE_VOID);
	m_pBlood->m_vPosition=posBREATH_BLOOD;
	m_pBlood->SetDispSide(eHitRight);
	AddSprite(m_pBlood);

	
	CREATE_SPRITE_SINGLE_FRAME(m_pEnd,ptBREATH_BLOOD_END,picBREATH_BLOOD_END,nLayer,true,false,JUDGE_POINTER_RE_VOID);
	m_pEnd->m_vPosition=m_pBlood->m_vPosition;
	AddSprite(m_pEnd); 
}

SpriteBreathBar::~SpriteBreathBar(void)
{
	//base class will delete the points
}

bool SpriteBreathBar::Draw(DWORD dwCurrentTime)
{
	if (m_fPercent<1e-6)
	{
		return false;
	}
	m_pBlood->SetDrawingPercent(1.0f-m_fPercent);
	m_pBlood->m_vPosition.x=posBREATH_BLOOD.x+picBREATH_BLOOD.nWidth*m_fPercent;
	m_pEnd->m_vPosition.x=m_pBlood->m_vPosition.x-picBREATH_BLOOD_END.nWidth;
	return SpriteCombined::Draw(dwCurrentTime);
}

void SpriteBreathBar::SetPercent( float fPercent )
{
	m_fPercent=fPercent;
}
